import axios from 'axios';
import Nproress from 'nprogress';
import 'nprogress/nprogress.css';

const mockAjax = axios.create({
  baseURL: '/mock',
  timeout: 3000
});
mockAjax.interceptors.request.use(config => {
  Nproress.start();
  return config;
});
mockAjax.interceptors.response.use(
  res => {
    Nproress.done();
    return res.data;
  },
  err => {
    Nproress.done();
    return Promise.reject(err => new Error(err.message));
  }
);
export default mockAjax;
